define([
  'jquery',
  'jquery-ui',
	'backbone',
  './programsModel',
  './programsView',
  './pubsub'
], function( $, _ui, Backbone, ProgramsModel, ProgramsView, pubsub ) {
  "use strict";

  // set Backbone's internal jQuery reference to our jQuery ref.
  Backbone.$ = $;

  var 
    exports = {},
    _programsView;

  exports.init = function(){
    _programsView = new ProgramsView({ model : ProgramsModel });
    _programsView.render();

  } ;


  //pubsub event handler
  pubsub.on( 'nextStep', function( message ) {
    var from = message.from,
        index = message.index,
        model = _programsView.model.at( index ),
        widgetIndex = model.get( 'currentIndex' ) + 1;
        model.set( { 'currentIndex' : widgetIndex});
    //Todo: send ajax call
    switch( from ){
      case 'intro':
        _programsView._reload( index );
        break;
      case 'day':
        _programsView._reload( index );
        break;
      default:
        console.log('from not recogonized');

    }




//    console.dir(_programsView.model);


  });

  return exports;

});